package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.ApplyToProgAddDTO;
import org.jsola.hr.dto.ApplyToProgUpdateDTO;
import org.jsola.hr.entity.ApplyToProgDO;
import org.jsola.hr.query.ApplyToProgQuery;
import org.jsola.hr.service.IApplyToProgService;
import org.jsola.hr.vo.ApplyToProgVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class ApplyToProgTestHelper extends BaseTestHelper {

    @Autowired
    private IApplyToProgService applyToProgService;

    /**
     * 生成add测试数据
     * @return ApplyToProgAddDTO
     */
    public ApplyToProgAddDTO getApplyToProgAddDTO(){
        ApplyToProgAddDTO applyToProgAddDTO = new ApplyToProgAddDTO();
        applyToProgAddDTO.setBusProgType(getRandomValue("varchar",32));
        applyToProgAddDTO.setBusProgId(getRandomValue("varchar",32));
        applyToProgAddDTO.setEmployType(getRandomValue("varchar",255));
        applyToProgAddDTO.setEmployRange(getRandomValue("varchar",255));
        applyToProgAddDTO.setMutex(false);
        applyToProgAddDTO.setCompanyId(getRandomValue("varchar",32));
        return applyToProgAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ApplyToProgUpdateDTO
     */
    public ApplyToProgUpdateDTO getApplyToProgUpdateDTO(ApplyToProgVO applyToProgVO){
        return applyToProgService.selectDOById(applyToProgVO.getId(), SITE_ID).to(ApplyToProgUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ApplyToProgQuery
     */
    public ApplyToProgQuery getApplyToProgQuery() {
        ApplyToProgQuery applyToProgQuery = new ApplyToProgQuery();
        List<ApplyToProgDO> applyToProgDOList = applyToProgService.list(new ApplyToProgDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(applyToProgDOList)) {
            ApplyToProgDO applyToProgDO = applyToProgDOList.get(0);
            applyToProgQuery = applyToProgDO.to(ApplyToProgQuery.class);
            if (applyToProgDO.getGmtCreate() != null) {
                applyToProgQuery.setGmtCreateStart(DateKit.getBeforeDay(applyToProgDO.getGmtCreate(),-1));
                applyToProgQuery.setGmtCreateEnd(DateKit.getBeforeDay(applyToProgDO.getGmtCreate(),1));
            }
            if (applyToProgDO.getGmtModified() != null) {
                applyToProgQuery.setGmtModifiedStart(DateKit.getBeforeDay(applyToProgDO.getGmtModified(),-1));
                applyToProgQuery.setGmtModifiedEnd(DateKit.getBeforeDay(applyToProgDO.getGmtModified(),1));
            }
        }
        return applyToProgQuery;
    }

    /**
     * 保存示例
     * @return ApplyToProgVO
     */
    public ApplyToProgVO saveApplyToProgExample(){
        ApplyToProgAddDTO addDTO = this.getApplyToProgAddDTO();
        ApplyToProgVO applyToProgVO = applyToProgService.save(addDTO,buildTokenUser());
        return applyToProgVO;
    }


}

